package com.zlt.controller.seeker;

import com.zlt.controller.BaseController;
import com.zlt.dto.QuestionDTO;
import com.zlt.entity.Question;
import com.zlt.entity.User;
import com.zlt.service.QuestionService;
import com.zlt.service.impl.QuestionServiceImpl;

import com.zlt.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;


@WebServlet("/question/*")
public class QuestionController extends BaseController {

    private QuestionService questionService=new QuestionServiceImpl();

    @Override
    protected void defaultMethod(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    /**
     * 提交反馈
     * @param req
     * @param resp
     * @return
     * @throws ServletException
     * @throws IOException
     */
    public Result submit (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //QuestionDTO questionDTO = ClassUtil.resolveRequest(QuestionDTO.class, req);

        String yourworks = req.getParameter("yourworks");
        try {
            boolean success = questionService.addQuestion(yourworks);
            return success ? Result.ok("反馈成功"):Result.error("反馈失败");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return Result.error("反馈失败");

    }

    public Result advise (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //QuestionDTO questionDTO = ClassUtil.resolveRequest(QuestionDTO.class, req);

        String yourworks = req.getParameter("yourworks");
        try {
            boolean success = questionService.insertQuestion(yourworks);
            return success ? Result.ok("反馈成功"):Result.error("反馈失败");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return Result.error("反馈失败");

    }





}
